package com.cms.intelligent_control.utils

import org.json.JSONArray
import org.json.JSONObject
import java.lang.Exception

fun isJsonStr(str: String): Boolean {
    try {
        JSONObject(str)
        return true
    } catch (e: Exception) {
    }
    return false
}

fun isAudioFile(filename: String): Boolean {
    return filename.endsWith(".mp3", true)
}

fun isVideoFile(filename: String): Boolean {
    return filename.endsWith(".mp4", true) || filename.endsWith(".m3u8", true)
}

fun isUrl(name: String): Boolean {
    return name.startsWith("http", true)
}


fun JSONArray.toList(): MutableList<JSONObject> {
    var list = mutableListOf<JSONObject>()
    for (i in 0 until this.length()) {
        list.add(this.getJSONObject(i))
    }
    return list
}